package org.swirrel.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

public class SwirrelActionListener extends AbstractSwirrelListener implements ActionListener {

    private final MethodCall actionPerformedCall;

    public SwirrelActionListener(MethodCall actionPerformedCall) {
        this.actionPerformedCall = actionPerformedCall;
        if(! checkSignature(actionPerformedCall, ActionEvent.class)) {
            throw new SwirrelException("Method must have none or one ActionEvent argument");
        }
    }

    public void actionPerformed(ActionEvent e) {
        call(actionPerformedCall, e);
    }
}
